package com.biostime.qdingding.modules.qd.service;



import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.biostime.qdingding.common.service.CrudService;
import com.biostime.qdingding.modules.cms.service.ArticleService;
import com.biostime.qdingding.modules.qd.api.dto.ArticleDto;
import com.biostime.qdingding.modules.qd.dao.CourseDao;
import com.biostime.qdingding.modules.qd.entity.Course;

/**
 * 父母指南service
 * @author chenweicheng
 * @version 2016-03-14
 */
@Service
@Transactional(readOnly = true)
public class ParentGuidanceService extends CrudService<CourseDao, Course> {
	
	@Autowired 
	ArticleService articleService;
	
	
	/**
	 * 	获取父母指南url
	 * @author  chenweicheng
	 * @version 2016-03-14
	 * @return
	 */
	public String getParentGuidanceUrl(HttpServletRequest request,String name){
		
		String parentGuidanceUrl = null;
		
		//项目url
		String projectUrl = request.getRequestURI();
		String url[] = projectUrl.split("/");
		if(url.length>3){
			projectUrl = url[0]+"/"+url[1]+"/"+url[2];
		}	
		
		//通过标题查找文章
		ArticleDto articleDto = articleService.getArticleByTitle(name);
		if(articleDto != null){
			parentGuidanceUrl = projectUrl+"/qd/article/show/"+articleDto.getId();
		}	
		
		return parentGuidanceUrl;
	}
}
